#include<iostream>
#include<cmath>
using namespace std;
int rose(int i){
	int a = i/1000,b = i/100%10,c = i/10%10,d = i%10;
	int ans = a*a*a*a+b*b*b*b+c*c*c*c+d*d*d*d;
	if(ans == i){
		return true;
	}else{
		return false;
	}
}
int main(){
	int n;
	cin >> n;
	if(n<1000 || n>9999){
		cout << "error!";
	}else{
		for(int i=1000;i<=n;i++){
			if(rose(i)){
				cout << i << endl;
			}
		}
	}
	return 0;
} 
